<?php
/**
 * CreateTime: 2023/11/21 14:05
 * User:LinQ
 */

namespace App\Models\Auth;

use App\Models\BasicModel;

class AuthModel extends BasicModel
{
    protected $table = 'auth';

    protected $primaryKey = 'auth_id';

    protected $fillable = [
        'auth_id',
        'com_id',
        'auth_name',
        'auth_code',
        'auth_type',
        'auth_url',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'auth_id' => 'integer',
        'com_id' => 'integer',
        'auth_name' => 'string',
        'auth_code' => 'string',
        'auth_type' => 'integer',
        'auth_url' => 'string',
        'created_at' => 'string',
        'updated_at' => 'string',
    ];

    protected $hidden = [
        'created_at',
        'updated_at',
    ];

    public function roles() {
        return $this->belongsToMany(RoleModel::class, 'role_auth','auth_id','role_id');
    }

    public function getAuthInfoByAuthCode($authCode){
        return $this->where('auth_code',$authCode)->first();
    }

}